      <h1 class="entry-title entry-title-single" itemprop="headline">REUSE_ALV_GRID_DISPLAY_LVC函数输入参数属性的应用</h1>

    <div class="entry-content entry-content-single entry-content-aside" itemprop="text">
      <p>前面我们讲过，<span class='wp_keywordlink_affiliate'><a href="http://www.sapjx.com/tag/alv" title="查看ALV中的全部文章" target="_blank">ALV</a></span> Grid <span class='wp_keywordlink'><a href="http://www.sapjx.com/tag/function" title="函数" target="_blank">函数</a></span>的输出有两个：REUSE_<span class='wp_keywordlink_affiliate'><a href="http://www.sapjx.com/tag/alv" title="查看ALV中的全部文章" target="_blank">ALV</a></span>_GRID_DISPLAY 和 REUSE_<span class='wp_keywordlink_affiliate'><a href="http://www.sapjx.com/tag/alv" title="查看ALV中的全部文章" target="_blank">ALV</a></span>_GRID_DISPLAY_LVC</p>
<p>两者的操作大同小异，只是后者能更好的和ALV容器结合使用，前后则不能；而在输入参数属性的结构上也有些差异。</p>
<p>本篇文章主要讲解下ALV<span class='wp_keywordlink'><a href="http://www.sapjx.com/tag/function" title="函数" target="_blank">函数</a></span>中输入参数的一些应用。</p>
<p>&nbsp;</p>
<p>首先了解下ALV函数输入参数的作用(粗体为常用参数):</p>
<p>I_INTERFACE_CHECK: 检查接口一致性</p>
<p>I_BYPASSING_BUFFER: 是否使用缓存</p>
<p>I_BUFFER_ACTIVE：是否激活缓存，如果每次显示ALV都是相同的字段目录，则该字段目录会被放到一特殊的缓存里，加快显示速度。</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#i_callback_program" title="i_callback_program参数属性">I_CALLBACK_PROGRAM</a></b>：调用ALV的程序名称</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#i_callback_pf_status_set" title="i_callback_pf_status_set参数属性">I_CALLBACK_PF_STATUS_SET</a></b>：ALV工具栏Subroutine（子程序）</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#i_callback_user_command" title="i_callback_user_command参数属性">I_CALLBACK_USER_COMMAND</a></b>：ALV User Command Subroutine（子程序），实现对应菜单项及相应事件功能</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#i_callback_top_of_page" title="i_callback_top_of_page参数属性">I_CALLBACK_TOP_OF_PAGE</a></b>：ALV抬头内容信息</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#i_callback_top_of_page" title="i_callback_html_top_of_page参数属性">I_CALLBACK_HTML_TOP_OF_PAGE</a></b>：ALV HTML格式抬头内容信息</p>
<p><span id="more-625"></span></p>
<p>I_CALLBACK_HTML_END_OF_LIST：ALV HTML格式页脚内容信息</p>
<p>I_STRUCTURE_NAME：为输出表数据结构的命名，指定了这个参数，域目录将会自动生成</p>
<p>I_BACKGROUND_ID：ALV背景图片Object ID</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#i_grid_title" title="i_grid_title参数属性">I_GRID_TITLE</a></b>：ALV 标题</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#i_grid_setting" title="i_grid_setting参数属性">I_GRID_SETTINGS</a></b>：GRID信息</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#is_layout" title="is_layout参数属性">IS_LAYOUT / IS_LAYOUT_LVC</a></b>：ALV输出布局样式</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#it_fieldcat" title="it_fieldcat参数属性">IT_FIELDCAT / IT_FIELDCAT_LVC</a></b>：设定显示的项目名称及输出设定</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#it_excluding" title="it_excluding参数属性">IT_EXCLUDING</a></b>：隐藏设置的ALV工具栏</p>
<p>IT_SPECIAL_GROUPS / IT_SPECIAL_GROUPS_LVC：若内表中一些字段通过SP_GROUP被分组在一起，必须为这些组传递组文本内表</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#it_sort" title="it_sort参数属性">IT_SORT / IT_SORT_LVC</a></b>：ALV排序设置</p>
<p>IT_FILTER / IT_FILTER_LVC：ALV过滤设置</p>
<p>IS_SEL_HIDE：替换或修改屏幕中select-option的值</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#is_variant" title="I_DEFAULT参数属性">I_DEFAULT</a></b>：用户是否可以定义默认的布局，&#8217;X'-可以定义默认布局，Space-不可以定义默认布局 （默认：X）</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#is_variant" title="I_SAVE参数属性">I_SAVE</a></b>：保存表格布局,&#8217;X'-只能保存全局变式；&#8217;U'-只能保存特定变式；&#8217;A'-都可以保存；Space-不能保存变式 （默认：space）</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#is_variant" title="IS_VARIANT参数属性">IS_VARIANT</a></b>：表格布局变式</p>
<p><b><a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#it_events" title="IT_EVENTS参数属性">IT_EVENTS</a></b>：设置事件, 类型为slis_t_event的内表（name：事件名称，form：事件的FORM）</p>
<p>IT_EVENT_EXIT：设置回调的方法的执行行为，表明用户所写的代码是在执行标准执行之前还是之后</p>
<p>IS_PRINT：后台打印的相关参数</p>
<p>I_SCREEN_START_COLUMN：以对话框形式显示的开始列</p>
<p>I_SCREEN_START_LINE：以对话框形式显示的开始行</p>
<p>I_SCREEN_END_COLUMN：以对话框形式显示的结束列</p>
<p>I_SCREEN_END_LINE：以对话框形式显示的结束行</p>
<p>I_HTML_HEIGHT_TOP：HTML抬头的高度</p>
<p>I_HTML_HEIGHT_END：HTML页脚的高度</p>
<p>IT_ALV_GRAPHICS：是否可以在图表中显示ALV</p>
<p>IT_HYPERLINK：使用超链接</p>
<p>&nbsp;</p>
<p><strong>下面详细介绍下常用的输入参数：</strong></p>
<p><b><a name="i_callback_program" id="i_callback_program">1. I_CALLBACK_PROGRAM 参数属性</a></b></p>
<p>定义调用程序名称，一般为当前程序sy-repid</p>
<p>&nbsp;</p>
<p><b><a name="i_callback_pf_status_set" id="i_callback_pf_status_set">2. I_CALLBACK_PF_STATUS_SET 参数</a></b></p>
<p>定义ALV屏幕菜单，此参数允许报表展现用户自定义的屏幕菜单，</p>
<p>参数类型为：SLIS_FORMNAME，指定自定义按钮的子FORM，该子FORM不显式的调用；</p>
<p>如：</p>
<pre class="brush: abap;">
i_callback_pf_status_set = 'FRM_SET_STATUS'
</pre>
<p>Form中的定义为：</p>
<pre class="brush: abap;">
FORM frm_set_status USING p_extab TYPE slis_t_extab.

SET PF-STATUS 'Z_ALV_STATUS' .

ENDFORM.                    " frm_set_status
</pre>
<p>&nbsp;</p>
<p>2.1). 没有自定义按钮时候，该参数可以不要，这时会显示ALV标准的按钮；</p>
<p>      当然这些按钮可以部分隐藏（见：<a href="http://www.sapjx.com/reuse_alv_grid_display_lvc.html#it_excluding" title="it_excluding参数属性">IT_EXCLUDING 参数属性</a>）；</p>
<p>2.2). 当我们使用自定义按钮后，ALV自带的标准按钮，则会失效，这时需要将一些必要的按钮在工具条补上；</p>
<p>2.3). 其中 &#8220;<strong>分隔符</strong>&#8221; 的插入方法为：在需要插入分隔符的方框内,选择菜单：<strong>Edit-&gt;Insert-&gt; Separator line</strong> 即可插入分隔符；</p>
<p>2.4). 下面是ALV中的标准工具的名称、代码、图标名称、快捷键：</p>
<table width="715" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="160"><b>名称</b></td>
<td width="130"><b>代码</b></td>
<td width="211"><b>图标名称</b></td>
<td width="213"><b>快捷键</b></td>
</tr>
<tr>
<td width="160">刷新</td>
<td width="130">REFRESH</td>
<td width="211">ICON_REFRESH</td>
<td width="213">F8（可随便更改）</td>
</tr>
<tr>
<td width="160">导出为EXCEL表格</td>
<td width="130">EXCEL</td>
<td width="211">无</td>
<td width="213">Shift-F8（可随便更改）</td>
</tr>
<tr>
<td width="160">ABC 分析</td>
<td width="130">&amp;ABC</td>
<td width="211">ICON_ABC</td>
<td width="213">Ctrl-F1</td>
</tr>
<tr>
<td width="160">按升序排列</td>
<td width="130">&amp;OUP</td>
<td width="211">ICON_SORT_UP</td>
<td width="213">Ctrl-F4</td>
</tr>
<tr>
<td width="160">设置过滤器</td>
<td width="130">&amp;ILT</td>
<td width="211">ICON_FILTER</td>
<td width="213">Ctrl-F5</td>
</tr>
<tr>
<td width="160">总计</td>
<td width="130">&amp;UMC</td>
<td width="211">ICON_SUM</td>
<td width="213">Ctrl-F6</td>
</tr>
<tr>
<td width="160">邮件查收件</td>
<td width="130">%SL</td>
<td width="211">ICON_MAIL</td>
<td width="213">Ctrl-F7</td>
</tr>
<tr>
<td width="160">更改布局…</td>
<td width="130">&amp;OL0</td>
<td width="211">ICON_ALV_VARIANTS</td>
<td width="213">Ctrl-F8</td>
</tr>
<tr>
<td width="160">选择布局…</td>
<td width="130">&amp;OAD</td>
<td width="211">ICON_ALV_VARIANT_CHOOSE</td>
<td width="213">Ctrl-F9</td>
</tr>
<tr>
<td width="160">保存布局…</td>
<td width="130">&amp;AVE</td>
<td width="211">ICON_ALV_VARIANT_SAVE</td>
<td width="213">Ctrl-F10</td>
</tr>
<tr>
<td width="160">信息</td>
<td width="130">&amp;INFO</td>
<td width="211">ICON_INFORMATION</td>
<td width="213">Ctrl-F12</td>
</tr>
<tr>
<td width="160">明细</td>
<td width="130">&amp;ETA</td>
<td width="211">ICON_SELECT_DETAIL</td>
<td width="213">Ctrl-Shift-F3</td>
</tr>
<tr>
<td width="160">按降序排列</td>
<td width="130">&amp;ODN</td>
<td width="211">ICON_SORT_DOWN</td>
<td width="213">Ctrl-Shift-F4</td>
</tr>
<tr>
<td width="160">删除过滤器</td>
<td width="130">&amp;ILD</td>
<td width="211">ICON_FILTER_UNDO</td>
<td width="213">Ctrl-Shift-F5</td>
</tr>
<tr>
<td width="160">小计</td>
<td width="130">&amp;SUM</td>
<td width="211">ICON_INTERMEDIATE_SUM</td>
<td width="213">Ctrl-Shift-F6</td>
</tr>
<tr>
<td width="160">Microsof</td>
<td width="130">&amp;VEXCEL</td>
<td width="211">ICON_XLS</td>
<td width="213">Ctrl-Shift-F7</td>
</tr>
<tr>
<td width="160">字处理</td>
<td width="130">&amp;AQW</td>
<td width="211">ICON_WORD_PROCESSING</td>
<td width="213">Ctrl-Shift-F8</td>
</tr>
<tr>
<td width="160">本地文件</td>
<td width="130">%PC</td>
<td width="211">ICON_EXPORT</td>
<td width="213">Ctrl-Shift-F9</td>
</tr>
<tr>
<td width="160">打印预览</td>
<td width="130">&amp;RNT_PREV</td>
<td width="211">ICON_LAYOUT_CONTROL</td>
<td width="213">Ctrl-Shift-F10</td>
</tr>
<tr>
<td width="160">图形</td>
<td width="130">&amp;GRAPH</td>
<td width="211">ICON_GRAPHICS</td>
<td width="213">Ctrl-Shift-F11</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>2.5). 一般情况下，可以快速拷贝标准程序的菜单栏，再进行修改、筛选；</p>
<p>操作步骤如下：</p>
<p>01). 进入 SE80，打开 Repository Information System;</p>
<p>02). 打开路径: Repository Information System-&gt; Program Library-&gt;Program SubObjects-&gt;GUI Status;</p>
<p>03). 在右边屏幕的程序名称（Program Name）输入框内输入标准程序名称：<b><span style="text-decoration: underline;">SAPLKKBL</span></b>，然后执行；</p>
<p>04). 在输出的列表中，找到 STANDARD 或 STANDARD_FULLSCREEN:<br />
<img src="http://www.sapjx.com/wp-content/uploads/2014/08/alv_gui_status.png" alt="alv_gui_status" width="757" height="535" class="alignnone size-full wp-image-627" /></p>
<p>05).双击进入菜单编辑后，拷贝到需要用到的程序中即可。</p>
<p>&nbsp;</p>
<p><b><a name="i_callback_user_command" id="i_callback_user_command">3. I_CALLBACK_USER_COMMAND 参数属性</a></b></p>
<p>响应菜单项及其相应事件，捕捉点击相应的按钮或双击等操作的 <span class='wp_keywordlink'><a href="http://www.sapjx.com/tag/function" title="Function" target="_blank">Function</a></span> Code(FCode)；</p>
<p>参数类型为：<strong>SLIS_FORMNAME</strong>，与 I_CALLBACK_PF_STATUS_SET 参数一样，为定义的子 FORM，不显式调用；</p>
<p>如：</p>
<pre class="brush: abap;">
i_callback_user_command = 'FRM_ ALV_USER_COMMAND'
</pre>
<p>Form 的定义为：</p>
<pre class="brush: abap;">
*&#038;---------------------------------------------------------------------*
*&#038;      Form  FRM_ALV_USER_COMMAN
*&#038;---------------------------------------------------------------------*
FORM frm_alv_user_command USING p_ucomm        TYPE sy-ucomm
                                p_rs_selfield  TYPE slis_selfield.
  CASE p_ucomm.
    WHEN '&#038;IC1' .   " 判断用户的动作
      "读取用户点击的当前行的一行内容
      READ TABLE i_tab INTO wa_tab INDEX p_rs_selfield-tabindex .
      IF p_rs_selfield-fieldname EQ 'CITYFROM'.
        "判断用户点击的是哪一列
        IF NOT wa_tab-cityfrom IS INITIAL .
          PERFORM frm_show_detail USING p_rs_selfield .   " 显示明细
        ENDIF.

      ELSEIF p_rs_selfield-fieldname EQ 'TCODE' .
        IF NOT wa_tab-tcode IS INITIAL .
          PERFORM frm_call_tran USING p_rs_selfield .     " 调用其他事务
        ENDIF .

      ELSEIF p_rs_selfield-fieldname EQ 'ICON_FOLDER' .

        PERFORM frm_open_folder USING p_rs_selfield .     " 打开文件

      ENDIF.

      CLEAR wa_tab.

    WHEN '&#038;SAVE_DATA' .
      PERFORM frm_save_data .                             " 保存数据

    WHEN 'PRINT' .
      PERFORM frm_print_data.                             " 打印数据

    WHEN 'EXCEL' .
      PERFORM frm_export .                                " 导出数据

  ENDCASE.

  p_rs_selfield-refresh = 'X' .   " 当用户在显式界面上对数据进行修改时，同时内表中的数据也随之刷新

ENDFORM.                    " frm_alv_user_command
</pre>
<p>&nbsp;</p>
<p>其中，标准按钮的FCode，可以通过类 <strong>CL_GUI_ALV_GRID</strong> 中的 <strong>Attributes</strong> 查看；</p>
<p>操作步骤：</p>
<p>01). 进入事务码SE24，输入类名称：CL_GUI_ALV_GRID，点击显示( Display )；</p>
<p>02). 切换到 Attributes 标签，找到自己需要的&#8221;属性&#8221;和&#8221;初始值&#8221;，这个初始值就是我们要找的标准按钮的FCODE；</p>
<p>&nbsp;</p>
<p><b>3.1 热点链接</b></p>
<p>热点链接，即 <span class='wp_keywordlink_affiliate'><a href="http://www.sapjx.com/tag/fieldcat" title="查看Fieldcat中的全部文章" target="_blank">Fieldcat</a></span>中 的 hotspot 属性；</p>
<p>设置之后，当用户点击带有热点的字段时，就会触发 Subroutine（FRM_USER_COMMAND）中的动作；</p>
<p>对于热点链接，所对应的FCode为 &#8220;<b>&amp;IC1</b>&#8220;；</p>
<p>示例如下：</p>
<pre class="brush: abap;">
lv_pos = lv_pos + 1 .
wa_fieldcat-col_pos       = lv_pos .
wa_fieldcat-fieldname     = 'MATNR' .
wa_fieldcat-scrtext_l     = '物料编号'.
wa_fieldcat-fix_column    = 'X' .
wa_fieldcat-hotspot       = 'X' .     " 热点，链接用
APPEND wa_fieldcat TO i_fieldcat .
CLEAR wa_fieldcat.

*&#038;---------------------------------------------------------------------*
*&#038;      Form  FRM_ALV_USER_COMMAND
*&#038;---------------------------------------------------------------------*
FORM frm_alv_user_command USING p_ucomm        TYPE sy-ucomm
                                p_rs_selfield  TYPE slis_selfield .
  CASE p_ucomm.

    WHEN '&#038;IC1' . "判断用户的动作

      "读取用户点击的当前行的一行内容
      READ TABLE i_tab INTO wa_tab INDEX p_rs_selfield-tabindex .

      IF p_rs_selfield-fieldname EQ 'MATNR'.             " 判断用户点击的是哪一列

        IF NOT wa_tab-matnr IS INITIAL .
          ………
        ENDIF.

      ELSEIF p_rs_selfield-fieldname EQ 'TCODE' .
        IF NOT wa_tab-tcode IS INITIAL .
          PERFORM frm_call_tran USING p_rs_selfield.     " 调用其他事务
        ENDIF .

      ENDIF.

      CLEAR wa_tab.

  ENDCASE.
  
  p_rs_selfield-refresh = 'X'.
  
ENDFORM.                    " frm_alv_user_command

</pre>
<p>&nbsp;</p>
<p><b>3.2 显示明细</b></p>
<p>在使用 REUSE_ALV_GRID_DISPLAY_LVC 时，会发现使用 REUSE_ALV_GRID_DISPLAY 时的双击显示行明细功能没有了；</p>
<p>这是<span class='wp_keywordlink'><a href="http://www.sapjx.com/tag/sap" title="SAP" target="_blank">SAP</a></span>标准程序决定的，REUSE_ALV_GRID_DISPLAY_LVC 已经取消了双击显示行明细功能。</p>
<p>当然，也可以点击工具栏中的放大镜按钮，直接查看明细；</p>
<p>如若想要实现双击显示明细，则可以直接执行FCode：&amp;ETA调用标准功能：</p>
<pre class="brush: abap;">
*&#038;---------------------------------------------------------------------*
*&#038;      Form  FRM_ALV_USER_COMMAND
*&#038;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->PA_UCOMM     text
*      -->PS_SELFIELD  text
*----------------------------------------------------------------------*
FORM frm_alv_user_command USING pa_ucomm TYPE sy-ucomm
                                ps_selfield TYPE slis_selfield.

  CASE pa_ucomm.
    WHEN '&#038;IC1'.          "双击
      pa_ucomm = '&#038;ETA'.  "查看明细
  ENDCASE.

ENDFORM.                    " FRM_ALV_USER_COMMAND
</pre>
<p>&nbsp;</p>
<p><b>3.3 调用其他事务</b></p>
<pre class="brush: abap;">
*&#038;---------------------------------------------------------------------*
*&#038;      Form  frm_alv_call_tran
*&#038;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM frm_alv_call_tran USING p_rs_selfield TYPE slis_selfield  .
  
  SET PARAMETER ID 'LIB' FIELD p_rs_selfield-value.
  
  CALL TRANSACTION 'SE37' AND SKIP FIRST SCREEN.
  
ENDFORM.                    " frm_alv_call_tran
</pre>
<p>其中，&#8221;<strong>LIB</strong>&#8220;是指：参数ID（PARAMETER ID）。</p>
<p>查找方法：</p>
<p>01). 用一个事务码进入屏幕界面，在输入框内按 F1；</p>
<p>02). 在弹出来的界面中点击”技术信息”按钮，在字段数据的最后一行，即为参数ID；</p>
<p>&#8220;SE37&#8243; 是指我们要调用的事务代码，<strong>AND SKIP FIRST SCREEN</strong> 表示跳过第一屏屏幕；</p>
<p>&nbsp;</p>
<p><b><a name="i_callback_top_of_page" id="i_callback_top_of_page">4. I_CALLBACK_TOP_OF_PAGE / I_CALLBACK_HTML_TOP_OF_PAGE 参数属性</a></b></p>
<p>I_CALLBACK_TOP_OF_PAGE 与 I_CALLBACK_HTML_TOP_OF_PAGE 参数属性都用于书写 ALV抬头标题信息，</p>
<p>只是区别在于后者支持 HTML格式；</p>
<p>参数类型：<strong>SLIS_FORMNAME</strong>，也与 I_CALLBACK_PF_STATUS_SET 参数一样，为定义的子FORM，不显式调用。</p>
<p>如：</p>
<pre class="brush: abap;">

i_callback_top_of_page       = 'FRM_TOP_OF_PAGE'

i_callback_html_top_of_page  = 'FRM_HTML_TOP_OF_PAGE'

</pre>
<p>其中，对应 FORM(FRM_HTML_TOP_OF_PAGE)的定义，需要引用类：<strong>CL_DD_DOCUMENT</strong>（动态文本类）来显示HTML格式。</p>
<p>如：</p>
<pre class="brush: abap;">
*&#038;---------------------------------------------------------------------*
*&#038;      Form  frm_html_top_of_page
*&#038;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_CL_DD    text
*----------------------------------------------------------------------*
FORM frm_html_top_of_page USING p_cl_dd TYPE REF TO cl_dd_document.
  
  …
  
ENDFORM.                    "frm_html_top_of_page
</pre>
<p>&nbsp;</p>
<p>下图是<span class='wp_keywordlink'><a href="http://www.sapjx.com/tag/sap" title="SAP" target="_blank">SAP</a></span>标准文档中的说明：<br />
<img src="http://www.sapjx.com/wp-content/uploads/2014/08/alv_i_callback_html_top_of_page_doc.png" alt="alv_i_callback_html_top_of_page_doc" width="669" height="505" class="alignnone size-full wp-image-629" /></p>
<p>&nbsp;</p>
<p>示例如下：</p>
<pre class="brush: abap;">
*&#038;---------------------------------------------------------------------*
*&#038;      Form  frm_html_top_of_page
*&#038;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_html_top_of_page USING p_cl_dd TYPE REF TO cl_dd_document.

  " 定义登录用户的描述
  DATA: l_name     TYPE string ,
        name_first LIKE adrp-name_first ,
        name_last  LIKE adrp-name_last .
  " 定义登录日期
  DATA: l_date TYPE string .

  " 定义缓冲区变量
  DATA: m_p      TYPE i ,
        m_buffer TYPE string .

  " 得到登录用户的描述
  SELECT SINGLE adrp~name_first
                adrp~name_last
    INTO (name_first,name_last)
    FROM adrp
    INNER JOIN usr21 ON adrp~persnumber = usr21~persnumber
   WHERE usr21~bname = sy-uname .

  IF sy-subrc = 0 .
    CONCATENATE name_last name_first INTO l_name .
  ELSE .
    l_name = sy-uname .
  ENDIF.
  CLEAR name_first .
  CLEAR name_last .

  " 拼接制表日期
  CONCATENATE sy-datum+0(2) '.'
              sy-datum+4(2) '.'
              sy-datum+6(2) '.'
         INTO l_date .

  m_buffer = '<HTML><H1>ALV DEMO</H1></HTML>' .
  CALL METHOD p_cl_dd->html_insert
    EXPORTING
      contents = m_buffer
    CHANGING
      position = m_p.

  " 输出制表人和制表日期
  CONCATENATE '<P>出表人：' l_name
              '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
              '出表日期：' l_date '</P>'
        INTO m_buffer .

  CALL METHOD p_cl_dd->html_insert
    EXPORTING
      contents = m_buffer
    CHANGING
      position = m_p.

ENDFORM.                    "frm_html_top_of_page


* ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
    i_callback_program          = sy-repid          " 当前程序
    i_callback_top_of_page      = 'FRM_TOP_OF_PAGE'
    i_callback_html_top_of_page = 'FRM_HTML_TOP_OF_PAGE'
    is_layout_lvc               = i_layout_lvc      " 属性内表
    it_fieldcat_lvc             = i_fieldcat_lvc[]  " 列明内表
    i_save                      = 'X'               " 是否保存布局
  TABLES
    t_outtab                    = i_tab             " 数据内表
  EXCEPTIONS
    program_error               = 1
    OTHERS                      = 2.
</pre>
<p>效果如图所示：</p>
<p><img src="http://www.sapjx.com/wp-content/uploads/2014/08/alv_i_callback_html_top_of_page_demo.png" alt="alv_i_callback_html_top_of_page_demo" width="565" height="238" class="alignnone size-full wp-image-628" /></p>
<p>&nbsp;</p>
<p><b>4.1 REUSE_ALV_COMMENTARY_WRITE 函数</b></p>
<p>上面文档中出现 REUSE_ALV_COMMENTARY_WRITE 函数，这里顺便了解下该函数的应用。</p>
<p>该函数与 CL_DD_DOCUMENT 类一样，用于 I_CALLBACK_TOP_OF_PAGE FORM 中输出抬头/页脚内容信息；</p>
<p>所以一般情况下：</p>
<p>I_CALLBACK_TOP_OF_PAGE Form 与 REUSE_ALV_COMMENTARY_WRITE 函数配合使用；</p>
<p>I_CALLBACK_HTML_TOP_OF_PAGE Form 与 CL_DD_DOCUMENT 类配合使用。</p>
<p>&nbsp;</p>
<p>REUSE_ALV_COMMENTARY_WRITE 函数包括一个必须参数，三个可选参数：</p>
<p><b>01). IT_LIST_COMMENTARY</b>（必须）：一个类型为 SLIS_T_LISTHEADER 的内表；</p>
<pre class="brush: abap;">
* Header table for top of page
TYPES: BEGIN OF slis_listheader,
         typ(1)  TYPE C,   " H = Header, S = Selection, A = Action
         key(20) TYPE C,
         info    TYPE slis_entry,
       END OF slis_listheader.

TYPES: slis_t_listheader TYPE slis_listheader OCCURS 1.
</pre>
<p>02). I_LOGO（可选）：图片/Logo 的 Object ID</p>
<p>03). I_END_OF_LIST_GRID（可选）：用于页脚的信息</p>
<p>04). I_ALV_FORM（可选）：是否用于 ALV 的FORM中，默认为：Space</p>
<p>&nbsp;</p>
<p>接下来，看下示例：</p>
<pre class="brush: abap;">
*&#038;---------------------------------------------------------------------*
*&#038;      Form  frm_top_of_page
*&#038;---------------------------------------------------------------------*
*       ALV 标题
*----------------------------------------------------------------------*
FORM frm_top_of_page.

  DATA: i_header  TYPE  slis_t_listheader,
        wa_header TYPE slis_listheader.

* 定义登录用户的描述
  DATA: l_name     TYPE string ,
        name_first LIKE adrp-name_first ,
        name_last  LIKE adrp-name_last .

* 定义登录日期
  DATA: l_date TYPE string .

* 得到登录用户的描述
  SELECT SINGLE
    adrp~name_first
    adrp~name_last
    INTO (name_first,name_last)
    FROM adrp
    INNER JOIN usr21 ON adrp~persnumber = usr21~persnumber
    WHERE usr21~bname = sy-uname .

  IF sy-subrc = 0 .
    CONCATENATE name_last name_first INTO l_name .
  ELSE .
    l_name = sy-uname .
  ENDIF.

  CLEAR name_first.
  CLEAR name_last.

* 拼接制表日期
  CONCATENATE sy-datum+0(4) '.'
              sy-datum+4(2) '.'
              sy-datum+6(2) INTO l_date.

  CONCATENATE '制表人：'   l_name INTO l_name .
  CONCATENATE '制表日期：' l_date  INTO l_date .

* 位于标题第一行
  wa_header-typ  = 'H'.
  wa_header-info = 'ALV DEMO' .
  APPEND wa_header TO i_header .
  CLEAR  wa_header .

* 相关内容信息，这里用于显示登录用户信息描述
  wa_header-typ  = 'S'.
  wa_header-key  = l_name .
  wa_header-info = l_date .
  APPEND wa_header TO i_header .
  CLEAR  wa_header .

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_header
      i_alv_form         = 'X'.

ENDFORM.                  "frm_top_of_page

* ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
    i_callback_program          = sy-repid          " 当前程序
    i_callback_top_of_page      = 'FRM_TOP_OF_PAGE'
    is_layout_lvc               = i_layout_lvc      " 属性内表
    it_fieldcat_lvc             = i_fieldcat_lvc[]  " 列明内表
    i_save                      = 'X'               " 是否保存布局
  TABLES
    t_outtab                    = i_tab             " 数据内表
  EXCEPTIONS
    program_error               = 1
    OTHERS                      = 2.
</pre>
<p>效果如图所示：</p>
<p><img src="http://www.sapjx.com/wp-content/uploads/2014/08/alv_i_callback_top_of_page_demo.png" alt="alv_i_callback_top_of_page_demo" width="777" height="402" class="alignnone size-full wp-image-630" /></p>
<p>&nbsp;</p>
<p><b>4.2 上传图片</b></p>
<p>01).通过事务码：<strong>OAER</strong>，进入 Business Document Navigator 参数界面；</p>
<p>02).输入值：</p>
<p>ClassName 输入：”PICTURES”；</p>
<p>Class Type 输入： “OT”</p>
<p><b>Object Key</b> 输入： 自定义ID名称（这里输入<b>ZJX_LOGO</b>），用于标记上上传图片的唯一标识</p>
<p>03).按F8执行后，进入到导航界面：</p>
<p><img src="http://www.sapjx.com/wp-content/uploads/2014/08/alv_upload_files_oaer.png" alt="alv_upload_files_oaer" width="723" height="508" class="alignnone size-full wp-image-632" /></p>
<p>04) 选择 PICTURES 节点后，在创建标签中，打开标准文档类型节点；</p>
<p><img src="http://www.sapjx.com/wp-content/uploads/2014/08/alv_upload_files_oaer_create.png" alt="alv_upload_files_oaer_create" width="587" height="215" class="alignnone size-full wp-image-633" /></p>
<p>05) 双击屏幕节点，会弹出文件框，直接上传现有的图片；</p>
<p>06) 选择文件后，输入描述与关键字，便于搜索查找；</p>
<p>07) 上传成功后，记录下Object Key：”<b>ZJX_LOGO</b>”</p>
<p>&nbsp;</p>
<p>然后在 ALV抬头中加入上传后的LOGO：</p>
<pre class="brush: abap;">
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_header
      i_logo             = 'ZJX_LOGO'  “ OAER 中的Object Key
      i_alv_form         = 'X'.
</pre>
<p>效果如图所示：<br />
<img src="http://www.sapjx.com/wp-content/uploads/2014/08/alv_reuse_alv_commentary_write_logo_demo.png" alt="alv_reuse_alv_commentary_write_logo_demo" width="794" height="438" class="alignnone size-full wp-image-631" /></p>
<p>&nbsp;</p>
<p>关于图片上传的内容，可以查看以下内容：</p>
<p>* Notes:</p>
<p>* 1) Logos &amp; wallpapers can be found in table BDS_CONN05</p>
<p>* 2) Transaction OAER can be used to create PICTURES.</p>
<p>* Run transaction OAER with class Class type = OT,</p>
<p>* and Object key with whatever name you want to create. In the</p>
<p>* next screen, right clicking on screen and import</p>
<p>&nbsp;</p>
<p>Steps for uploading Logo :-:</p>
<p>1.  Goto the transaction OAER</p>
<p>2.  Enter the class name as &#8216;PICTURES&#8217;</p>
<p>3.  Enter the class type as &#8216;OT&#8217;</p>
<p>4.  Enter the object key as the name of the logo you wish to give</p>
<p>5.  Execute</p>
<p>6.  Then in the new screen select Standard doc. types in bottom window</p>
<p>Click on the Screen icon</p>
<p>Now, it will ask for the file path where you have to upload the logo</p>
<p>7.  Now you can use this logo in REUSE_ALV_COMMENTARY_WRITE</p>
<p>or</p>
<p>Import Logo and Background Picture for Reporting</p>
<p>In this step, you can import a customer-specific logo and a background picture into the R/3 System.</p>
<p>These will be displayed in the header area of reports in HR Funds and Position Management.</p>
<p>From the SPRO:</p>
<p>HR Funds and Position Management &#8211;&gt; Dialog Control &#8211;&gt; Customize Reporting Interface &#8211;&gt; Import Logo and Background Picture for Reporting.</p>
<p>Activities</p>
<p>1. Enter the Name of your logo/background picture as an object key in the initial screen.</p>
<p>2. Make sure that the class name is PICTURES, and the class type is OT.</p>
<p>3. Choose Execute.</p>
<p>4. Double-click the document type Picture on the Create tab page.</p>
<p>A dialog box will appear in which you can enter the path in which the logo/background picture can be found.</p>
<p>5. Enter the path and choose Open.  The logo will be uploaded into the current R/3 System.</p>
<p>If the logo/background picture is to be transported into other systems as well, choose Transport.</p>
<p>6. Return to the initial screen and repeat the procedure after having entered the Name of your background picture as an object key.</p>
<p>Please note that the logo/background picture can only be displayed in ALV-based reports with an HTML header.</p>
<p>Manually programmed reports such as business distribution plans are not based on the ALV.</p>
<p>If you have selected several initial objects, ALV-based reports in HR Funds and Position Management will automatically use a hiearchical-sequential display.</p>
<p>A logo is not displayed here either. Note also that the logo cannot be printed (see print preview in program).</p>
<p>Make sure that the logo does not exceed a height of 100 pixels because it would mean that the header of the report will be scrollable.</p>
<p>&nbsp;</p>
<p><b><a name="i_grid_title" id="i_grid_title">5. I_GRID_TITLE 参数属性</a></b></p>
<p>该参数为 ALV 小标题，位于 ALV 抬头信息下方；示例如下：</p>
<pre class="brush: abap;">

DATA: i_grid_title TYPE lvc_title .

i_grid_title = '小标题' .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
    i_callback_program          = sy-repid          " 当前程序
    i_callback_top_of_page      = 'FRM_TOP_OF_PAGE'
    i_callback_html_top_of_page = 'FRM_HTML_TOP_OF_PAGE'
    i_grid_title                = i_grid_title
    is_layout_lvc               = i_layout_lvc      " 属性内表
    it_fieldcat_lvc             = i_fieldcat_lvc[]  " 列明内表
    i_save                      = 'X'               " 是否保存布局
  TABLES
    t_outtab                    = i_tab             " 数据内表
  EXCEPTIONS
    program_error               = 1
    OTHERS                      = 2.
</pre>
<p>效果如图所示：<br />
<img src="http://www.sapjx.com/wp-content/uploads/2014/08/alv_grid_title_demo.png" alt="alv_grid_title_demo" width="566" height="275" class="alignnone size-full wp-image-626" /></p>
<p>&nbsp;</p>
<p><b><a name="i_grid_setting" id="i_grid_setting">6. I_GRID_SETTINGS 参数属性</a></b></p>
<p>该参数用于设置Grid相关参数（打印、单元格回调）；</p>
<p>类型为：LVC_S_GLAY，该结构包括：</p>
<p>01) COLL_TOP_P：最小化 TOP_OF_PAGE</p>
<p>02) COLL_END_L：最小化 END_OF_LIST</p>
<p>03) TOP_P_ONLY：仅打印TOP_OF_PAGE</p>
<p>04) EOL_P_ONLY：仅打印END_OF_LIST</p>
<p>05) NO_COLWOPT：不优化打印的列宽</p>
<p><b>06) EDT_CLL_CB</b>：退出可编辑单元格时回调</p>
<p>其中，常用的是 <strong>EDT_CLL_CB</strong> 字段，该字段用于回调输入的变量；</p>
<p>即，当我们在ALV的显示界面可编辑字段上修改了数据，回车后会回调我们修改的数据到内表中，并对其修改；</p>
<p>这个字段在编辑操作中很关键。</p>
<p>&nbsp;</p>
<p>示例代码如下：</p>
<pre class="brush: abap;">
* 定义回调变量
DATA: i_grid_settings TYPE  lvc_s_glay.

i_grid_settings-edt_cll_cb  = 'X' .

* 在ALV中使用
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
    i_callback_program = sy-repid
    is_layout_lvc      = i_layout_lvc
    it_fieldcat_lvc    = i_fieldcat_lvc[]
    i_grid_settings    = i_grid_settings
    i_save             = 'X'
  TABLES
    t_outtab           = i_tab
  EXCEPTIONS
    program_error      = 1
    OTHERS             = 2.
</pre>
<p>&nbsp;</p>
<p><b><a name="is_layout" id="is_layout">7. IS_LAYOUT/ IS_LAYOUT_LVC 参数属性</a></b></p>
<p>关于该参数，前面文章《<a href="http://www.sapjx.com/alv-fieldcat-and-layout.html">ALV简介和Fieldcat与Layout相关参数属性</a>》中已经讲述过其相关参数属性；</p>
<p>可查看相关参数属性：<a href="http://www.sapjx.com/alv-fieldcat-and-layout.html#layout">Layout属性</a>，这里列举下常用的一些属性:</p>
<p><strong>7.1 设置grid的字段列宽度自动适应</strong></p>
<pre class="brush: abap;">
i_layout-colwidth_optimize = 'X'
</pre>
<p><strong>7.2 设置grid的行颜色变换显示</strong></p>
<pre class="brush: abap;">
i_layout-zebra  = 'X'
</pre>
<p><strong>7.3 设置弹出窗口的标题栏</strong></p>
<pre class="brush: abap;">
i_layout-detail_titlebar = '详细内容'
</pre>
<p><strong>7.4 设置grid的多行选择列，其中box必须为内表的一列,为一个字符长度</strong></p>
<pre class="brush: abap;">
i_layout-box_fieldname= 'BOX'
</pre>
<p><strong>7.5 设置grid是否显示行分割线</strong></p>
<pre class="brush: abap;">
i_layout-no_vline= 'X'
</pre>
<p><strong>7.6 设置grid的合计行显示在明细的上面</strong></p>
<pre class="brush: abap;">
i_layout-totals_before_items= 'X'
</pre>
<p><strong>7.7 设置grid不显示弹出明细显示窗口</strong></p>
<pre class="brush: abap;">
i_layout-detail_popup= 'X'
</pre>
<p><strong>7.8 设置grid显示led列， light为内表字段，,一个字符长，,值范围为1-3</strong></p>
<pre class="brush: abap;">
i_layout-excp_fname= 'light'
</pre>
<p><strong>7.9 设置grid的没有标题</strong></p>
<pre class="brush: abap;">
i_layout-no_colhead = 'X'
</pre>
<p>&nbsp;</p>
<p><b><a name="it_fieldcat" id="it_fieldcat">8. IT_FIELDCAT/ IT_FIELDCAT_LVC 参数属性</a></b></p>
<p>与 IS_LAYOUT/ IS_LAYOUT_LVC 参数一样，前面文章《<a href="http://www.sapjx.com/alv-fieldcat-and-layout.html">ALV简介和Fieldcat与Layout相关参数属性</a>》中已经讲述过该参数的相关属性；</p>
<p>可查看相关参数属性：<a href="http://www.sapjx.com/alv-fieldcat-and-layout.html#fieldcat">Fieldcat属性</a>，这里列举下常用的一些属性：</p>
<p><b>8.1 单列优化宽度</b></p>
<pre class="brush: abap;">
wa_fieldcat-col_opt   = 'X'.
</pre>
<p>&nbsp;</p>
<p><b>8.2 单列求和或者取消求和，添加属性</b></p>
<pre class="brush: abap;">
wa_fieldcat-do_sum    = ‘X’.   " 求和
wa_fieldcat-no_sum    = ‘X’.   " 取消求和
</pre>
<p>&nbsp;</p>
<p>如若在IS_LAYOUT属性中加上下列属性，则求和后的行就会在第一行出现</p>
<pre class="brush: abap;">
i_layout-totals_bef   = 'X'.
</pre>
<p>&nbsp;</p>
<p><b>8.3 对齐方式</b></p>
<pre class="brush: abap;">
wa_fieldcat-just    = 'L' .   " 左对齐
wa_fieldcat-just    = 'C' .   " 居中对齐
wa_fieldcat-just    = 'R' .   " 右对齐
</pre>
<p>默认情况下，<span class='wp_keywordlink'><a href="http://www.sapjx.com/tag/sap-abap" title="ABAP" target="_blank">ABAP</a></span> 的各种数据类型优默认的对其方式：</p>
<p>字符串是默认为左对齐；</p>
<p>货币、数量默认为右对齐；</p>
<p>&nbsp;</p>
<p><b>8.4 以图标方式输出</b></p>
<p>需要作为图标输出，首先要引入图标的信息：Include &lt;list&gt;;</p>
<p>然后在内表中添加显示图标的字段名称；</p>
<p>在 <span class='wp_keywordlink_affiliate'><a href="http://www.sapjx.com/tag/fieldcat" title="查看Fieldcat中的全部文章" target="_blank">Fieldcat</a></span> 添加属性的时候，则可以为内表显示图标的字段添加相关图标。</p>
<p>&nbsp;</p>
<p>示例如下：</p>
<pre class="brush: abap;">
* 内表字段
i_tab-icon_folder = icon_object_folder.

* FieldCat 属性
lv_pos = lv_pos + 1 .
wa_fieldcat-col_pos    = lv_pos .
wa_fieldcat-fieldname  = 'ICON_FOLDER'.
wa_fieldcat-scrtext_l  = 'ICON' .
wa_fieldcat-icon       = 'X' .      "启用图标
wa_fieldcat-hotspot    = 'X' .
APPEND wa_fieldcat TO i_fieldcat .

CLEAR wa_fieldcat .
</pre>
<p>这样图标就可以在ALV界面中显示了，其中添加&#8221;热点&#8221;的目的是为了当用户点击该图标的时候，可以触发一系列的操作，如文件的选择等等；</p>
<p>&nbsp;</p>
<p>注意：图标的名称用事务码&#8221;<strong>ICON</strong>&#8220;进入后,第二列就是图标代码，根据需要进行选择；</p>
<p>&nbsp;</p>
<p><b>8.5 单元格的F1、F4帮助</b></p>
<p><strong>8.5.1 F1帮助</strong></p>
<p>在Fieldcat的RollName属性中，添加指定的数据元素，即可激活F1帮助；如：</p>
<pre class="brush: abap;">
wa_fieldcat-rollname  = 'PS_PSPID' .  " 指定数据元素
</pre>
<p>&nbsp;</p>
<p><strong>8.5.2 F4帮助</strong></p>
<p>在Fieldcat中添加下列属性：</p>
<pre class="brush: abap;">
wa_fieldcat-ref_field = 'PSPID'. " 对应DDIC中的参考字段

wa_fieldcat-ref_table = 'PROJ'.  " 对应DDIC中的参考表
</pre>
<p>这样在ALV的显示界面，在该字段处就可以按F4来查看相关的内容了；</p>
<p>&nbsp;</p>
<p><b>8.6 字段类型保留</b></p>
<p>对于货币或数量字段，需要在其设置字段中再添加一个&#8221;指定数据类型&#8221;的属性，如下：</p>
<pre class="brush: abap;">
* 货币字段
wa_fieldcat-datatype  = 'CURR' .     " 指定数据类型

* 数量字段
wa_fieldcat-datatype  = 'QUAN' .     " 指定数据类型
wa_fieldcat-inttype   = 'C' .      " 数据类型以C类型输出
</pre>
<p>&nbsp;</p>
<p><b><a name="it_excluding" id="it_excluding">9. IT_EXCLUDING 参数属性</a></b></p>
<p>该参数可对ALV标准工具栏隐藏不必要的功能；</p>
<p>对于该参数的应用，需要知道ALV标准按钮对应的 FCode，这里在上面讲过，可以查看 <strong>CL_GUI_ALV_GRID</strong> 类的属性及其初始值；</p>
<p>示例代码如下：</p>
<pre class="brush: abap;">
* 定义隐藏标准按钮的变量
DATA: wa_excluding TYPE slis_t_extab ,
      it_excluding   TYPE slis_extab .

* 将需要隐藏的标准按钮的"FCODE"添加到内表IT_EXCLUDING中
wa_excluding-fcode = '&#038;ABC' .
APPEND wa_excluding TO it_excluding.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
    i_callback_program = sy-repid
    is_layout_lvc      = i_layout_lvc
    it_fieldcat_lvc    = i_fieldcat_lvc[]
    it_excluding       = it_excluding      " 添加隐藏按钮的属性参数
    i_save             = 'X'
  TABLES
    t_outtab           = i_tab
  EXCEPTIONS
    program_error      = 1
    OTHERS             = 2.
</pre>
<p>&nbsp;</p>
<p><b><a name="it_sort" id="it_sort">10. IT_SORT/ IT_SORT_LVC 参数属性</a></b></p>
<p>ALV 字段排序设置；</p>
<p>两个参数的类型定义虽然不一样，但结构是一样的，所以操作上并无差异；</p>
<p>下面查看下IT_SORT参数的类型结构定义：</p>
<pre class="brush: abap;">
TYPES: BEGIN OF slis_sortinfo_alv,
         spos      LIKE alvdynp-sortpos,   “ 排序顺序序号
         fieldname TYPE slis_fieldname,    “ 排序内表字段名称
         tabname   TYPE slis_fieldname,    “ 排序内表名称
         up        LIKE alvdynp-sortup,    “ 升序
         down      LIKE alvdynp-sortdown,  “ 降序
         group     LIKE alvdynp-grouplevel,“ 
         subtot    LIKE alvdynp-subtotals, “ 输出小计
         comp(1)   TYPE c,
         expa(1)   TYPE c,
         obligatory(1) TYPE c,
       ENF OF slis_sortinfo_alv.
</pre>
<p>&nbsp;</p>
<p>示例代码如下：</p>
<pre class="brush: abap;">

* 定义排序变量
DATA: wa_sort_lvc TYPE lvc_s_sort ,
      it_sort_lvc TYPE lvc_t_sort .

* 设置排序参数
wa_sort_lvc-spos        = 1 .           " 排序顺序
wa_sort_lvc-fieldname   = 'WERKS' .  " 排序字段
wa_sort_lvc-up          = 'X' .         " 升序
APPEND wa_sort_lvc TO it_sort_lvc .
CLEAR wa_sort_lvc .

wa_sort_lvc-spos        = 2 .           " 排序顺序
wa_sort_lvc-fieldname   = ‘matnr’ .  " 排序字段
wa_sort_lvc-up          = 'X' .         " 升序
APPEND wa_sort_lvc TO it_sort_lvc .
CLEAR wa_sort_lvc .

* ALV 中添加排序属性
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
    i_callback_program          = sy-repid          "
    is_layout_lvc               = i_layout_lvc      "
    it_fieldcat_lvc             = i_fieldcat_lvc[]  "
    it_sort_lvc                 = it_sort_lvc
  TABLES
    t_outtab                    = i_tab             "
  EXCEPTIONS
    program_error               = 1
    OTHERS                      = 2.
</pre>
<p>&nbsp;</p>
<p><b><a name="is_variant" id="is_variant">11. I_DEFAULT/ I_SAVE/ IS_VARIANT 参数属性</a></b></p>
<p>这三个参数都是用于ALV 布局的保存设置：</p>
<p>01). I_DEFAULT参数用于设置用户是否可以定义默认的布局: &#8217;X' 可以定义默认布局， SPACE 不可以定义默认布局 （默认：X）</p>
<p>02). I_SAVE 参数 保存表格布局： &#8217;X' 只能保存全局变式 &#8217;U' 只能保存特定变式 &#8217;A' 都可以保存 SPACE 不能保存变式 （默认：space）</p>
<p>03). IS_VARIANT 参数用于启用用户表格布局变式</p>
<p><img src="http://www.sapjx.com/wp-content/uploads/2014/08/alv_variant.png" alt="alv_variant" width="425" height="85" class="alignnone size-full wp-image-634" /></p>
<p>&nbsp;</p>
<p><b><a name="it_events" id="it_events">12. IT_EVENTS 参数属性</a></b></p>
<p>IT_EVENTS 参数属性,传入一个 <strong>SLIS_T_EVENT</strong> 类型的内表，设置相应处理FORM；</p>
<p>通过与REUSE_ALV_EVENTS_GET函数配合使用，可自定义ALV事件。</p>
<p>&nbsp;</p>
<p>首先，查看下SLIS_T_EVENT的类型结构定义，如下所示：</p>
<pre class="brush: abap;">
*--- Structure for event handling
TYPES: BEGIN OF slis_alv_event,
        name(30),
        form(30),
      END OF slis_alv_event.
TYPES: slis_t_event TYPE slis_alv_event OCCURS 0.
</pre>
<p>&nbsp;</p>
<p>再看下 <strong>REUSE_ALV_EVENTS_GET</strong> 函数，该函数可以获取ALV中现有的事件，其参数也较为简单：</p>
<p>Import 参数：I_LIST_TYPE，类型为SLIS_LIST_TYPE，即为ALV事件的序号，其输入可以为：0,1,2,4</p>
<p>Export 参数：ET_EVENTS，类型为 <strong>SLIS_T_EVENT</strong>；</p>
<p>&nbsp;</p>
<p>接下来，查看下示例：</p>
<pre class="brush: abap;">
* 全局变量
DATA: gv_index  TYPE sy_tabix.

DATA: gt_events TYPE slis_t_event.     "ALV 事件

*&#038;---------------------------------------------------------------------*
*&#038;      Form  FRM_GET_EVENT
*&#038;---------------------------------------------------------------------*
FORM frm_get_event.

  DATA formname_top_of_page TYPE slis_formname VALUE 'FRM_TOP_OF_PAGE'.
  DATA lw_events            TYPE LINE OF slis_t_event.

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = gt_events
    EXCEPTIONS
      list_type_wrong = 1
      OTHERS          = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

* 修改TOP_OF_PAGE以加入表头，设置处理子程序为'FRM_TOP_OF_PAGE'
  CLEAR gv_index.
  CLEAR lw_events.
  READ TABLE gt_events INTO lw_events WITH KEY
  name = slis_ev_top_of_page.

  IF sy-subrc = 0.

    gv_index = sy-tabix.
    MOVE 'FRM_TOP_OF_PAGE' TO lw_events-form.
    MODIFY gt_events FROM lw_events INDEX gv_index.

  ELSE.

    lw_events-form = 'FRM_TOP_OF_PAGE'.
    lw_events-name = slis_ev_top_of_page.
    APPEND lw_events TO gt_events.

  ENDIF.

  lw_events-name = 'CALLER_EXIT'.
  lw_events-form = 'FRM_BUTTON'.
  APPEND lw_events TO gt_events.

ENDFORM.                    " FRM_GET_EVENT


*&#038;---------------------------------------------------------------------*
*&#038;      Form  frm_button
*&#038;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_button USING e_grid TYPE slis_data_caller_exit.


*
ENDFORM.                    "FRM_BUTTON
</pre>
<p>&nbsp;</p>
<p>通过IT_EVENTS 参数属性，就可以为ALV添加自定义的事件 CALLER_EXIT；</p>
<p>其事件的相应处理，则放在FORM中。</p>
